<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./assset/bootstrap@5.3.0/css/bootstrap.min.css">
</head>
<body>
    <!-- 导航条 -->
    <nav class="navbar navbar-expand-lg bg-primary">
        <div class="container-fluid">
          <a class="navbar-brand" href="#">Navbar</a>
          <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
          <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav me-auto mb-2 mb-lg-0">
              <li class="nav-item">
                <a class="nav-link active" aria-current="page" href="#">Home</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">Link</a>
              </li>
              <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                  Dropdown
                </a>
                <ul class="dropdown-menu">
                  <li><a class="dropdown-item" href="#">Action</a></li>
                  <li><a class="dropdown-item" href="#">Another action</a></li>
                  <li><hr class="dropdown-divider"></li>
                  <li><a class="dropdown-item" href="#">Something else here</a></li>
                </ul>
              </li>
              <li class="nav-item">
                <a class="nav-link disabled">Disabled</a>
              </li>
            </ul>
            <form class="d-flex" role="search">
              <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
              <button class="btn btn-outline-success" type="submit">Search</button>
            </form>
          </div>
        </div>
      </nav>
    <!-- \导航条 -->

    <!-- 表单 -->
    <div class="container mt-5">
        <div class="row justify-content-center">
            <div class="col-8 col-lg-4">
                <div class="card">
                   
                    <div class="card-body">
                        <form id="loginForm">
                            <div class="mb-3">
                              <label for="exampleInputEmail1" class="form-label">Email address</label>
                              <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
                              <div id="emailHelp" class="form-text">We'll never share your email with anyone else.</div>
                            </div>
                            <div class="mb-3">
                              <label for="exampleInputPassword1" class="form-label">Password</label>
                              <input type="password" class="form-control" id="exampleInputPassword1">
                            </div>
                            <div class="mb-3 form-check">
                              <input type="checkbox" class="form-check-input" id="exampleCheck1">
                              <label class="form-check-label" for="exampleCheck1">Check me out</label>
                            </div>
                            <button type="button" id="loginBtn" class="btn btn-primary d-block w-100">登录</button>
                        </form>
                </div>
            </div>


               
            </div>
        </div>
    </div>
    
    <!-- \表单 -->
    

    <script src="./assset/bootstrap@5.3.0/js/bootstrap.bundle.min.js"></script>
    <script src="./assset/just-validate@4.3.0/just-validate.production.min.js"></script>
    <script>

     let loginBtn=  document.querySelector("#loginBtn");
     let emailInput=document.querySelector("#exampleInputEmail1");
     let pwdInput= document.querySelector("#exampleInputPassword1");

      loginBtn.addEventListener('click',()=>{
       //通过fecth发送异步请求
         let data={email:emailInput.value,pwd:pwdInput.value};
         fetch("login", {
             method: "POST",
             headers: {
                 "Content-Type": "application/json",
             },
             body: JSON.stringify(data),
         }).then(response=>response.json()).then((data)=>{
             // if(data.flag){
             //     //跳转到index.html
             //     location.href="index.html"
             // }
             if(data.flag){
                 //将数据存储到sessionStorage
                 sessionStorage.setItem("info",JSON.stringify(data.data));
                 location.href="index.html"
             }
         });
     })
    </script>
</body>
</html>